/**
 * 
 */
package com.williamoneil.charts.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.williamoneil.charts.shared.ChartData;

/**
 * @author Gudipati
 *
 */
public class ChartMainPanel extends DockLayoutPanel {

	private ChartServiceAsync chartService = null;
	
	private ChartHeaderPanel header = null;
	private ChartPanel chart = null;
	
	public ChartMainPanel() {
		super(Unit.PX);
		
		//super.setWidth("100%");
		//super.setHeight("100%");
		
		header = new ChartHeaderPanel();
		chart = new ChartPanel();
		
		super.addNorth(header, 30);
		super.add(chart);
		
		Window.addResizeHandler(new ResizeHandler() {
			@Override
			public void onResize(ResizeEvent event) {
				chart.resized();
			}
		});
	}

	/**
	 * @return the header
	 */
	public ChartHeaderPanel getHeader() {
		return header;
	}
	
	/**
	 * @return the chart
	 */
	public ChartPanel getChart() {
		return chart;
	}

	/**
	 * @return the chartService
	 */
	public ChartServiceAsync getChartService() {
		if(chartService == null) {
			chartService = (ChartServiceAsync) GWT.create(ChartService.class);
			//((ServiceDefTarget) chartService).setServiceEntryPoint( GWT.getModuleBaseURL() + "/charts/chart");
		}
		
		return chartService;
	}
	
	public void handleChartDataResponse(final ChartData symbolChartData, final ChartData benchmarkChartData) {
		getHeader().setSymbolInformation(symbolChartData.getSymbol());
		getChart().drawPriceVolumeChart(symbolChartData, benchmarkChartData);
	}
}
